/*
程序创建者:Gavin向
创建时间:2022/2/6
B站账号:1915541970
编程语言:C++
*/
#include <iostream>
#include <string>
#include <cstdlib>//随机数头文件 

using namespace std;

int index = 0;
int sign_index = 0; 
int result;
int arr[4] = {0,0,0,0};//创建一个数组 

int initialization(){
	int *ptr = arr;//获得地址 
	for(int i=0;i<4;i++){
		cout <<"元素"<< *ptr <<"-";
		cout << "地址为:" << ptr<<endl;
		ptr++; 
	}
	
} 
int random(int min_number,int max_number){//定义生成随机树的函数 
	return rand()%max_number + min_number;//返回结果 
}
int multiplication(int a,int b,int c,int d){//乘法函数 
	index = 0;
	int r1,r2,r3,r4; 
	if(a*b*c*d == 24){//A*B*C*D情况 
		index = 1;
		cout <<a<<"*"<<b<<"*"<<c<<"*"<<d<<"=24"<<endl; 
	}
	if(index == 0){//A*B情况 
		for(int k=0;k<120;k++){
			r1 = arr[random(0,4)]; 
			r2 = arr[random(0,3)];
			int answer = r1*r2; 
			//cout <<r1<<"*"<<r2<<"="<<answer<<endl; 
			if(answer == 24){
				index = 1;
			 	cout <<"最终结果:"<<r1<<"*"<<r2<<"=24"<<endl; 
				break; 
			}
		} 
	}
	if(index == 0){//A*B*C情况 
		for(int k=0;k<120;k++){
			r1 = arr[random(0,4)]; 
			r2 = arr[random(0,3)];
			r3 = arr[random(0,2)];
			int answer = r1*r2*r3; 
			//cout <<r1<<"*"<<r2<<"*"<<r3<<"="<<answer<<endl; 
			if(answer == 24){
				index = 1;
			 	cout <<"最终结果:"<<r1<<"*"<<r2<<"*"<<r3<<"=24"<<endl; 
				break; 
			}
		} 
	}
	if(index == 0){//AB*C情况 
		for(int k=0;k<120;k++){
			r1 = arr[random(0,4)]; 
			r2 = arr[random(0,3)];
			r3 = arr[random(0,2)];
			int answer = (r1*10+r2)*r3; 
			//cout <<r1<<r2<<"*"<<r3<<"="<<answer<<endl; 
			if(answer == 24){
				index = 1;
			 	cout <<"最终结果:"<<r1<<r2<<"*"<<r3<<"=24"<<endl; 
				break; 
			}
		} 
	}
}

int main(void){ //主函数
	cout <<"请输入四个分别要计算的数字(每个数字之间输入一个空格,运算为乘法):" ;
	for(int i=0;i<4;i++){//for循环输入四个数
		cin >> index;
		arr[i] = index;//存入数组arr中
	}
	multiplication(arr[0],arr[1],arr[2],arr[3]);//运行乘法函数
	return 0;//结束所有程序 
}